package cn.darkhorse.mesadmin.controller.ticket;


import cn.darkhorse.ticket.constants.TicketConstants;
import cn.darkhorse.ticket.production.pojo.BatchPersons;
import cn.darkhorse.ticket.production.service.BatchPersonsDTO;
import cn.darkhorse.ticket.production.service.TicketTaskService;
import cn.darkhorse.ticket.production.vo.TicketTaskListVO;
import cn.darkhorse.ticket.production.vo.TicketTaskScheduleVO;
import cn.darkhorse.ticket.production.vo.TicketTaskViewVO;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 工序任务 前端控制器
 * </p>
 *
 * @author wangxinghui
 * @since 2024-01-30
 */
@RestController
@RequestMapping("/ticket/ticketTask")
public class TicketTaskController extends BaseController{
	
	@Resource
	private TicketTaskService taskService;
	
	
	/**
	 * 列表
	 * @param taskDTO
	 * @return
	 */
	@RequestMapping(value = "/list",method = RequestMethod.GET)
	public TableDataInfo list(TicketTaskService.TicketTaskDTO taskDTO){
		startPage();
		List<TicketTaskListVO> voList = taskService.list(taskDTO);
		return getDataTable(voList);
	}
	
	/**
	 * 查看
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/view",method = RequestMethod.GET)
	public AjaxResult list(Long id){
		if(null == id){
			return AjaxResult.error("缺失参数值！");
		}
		TicketTaskViewVO vo = taskService.view(id);
		return AjaxResult.success(vo);
	}
	
	/**
	 * 批量设置质检人
	 * @param personsDTO
	 * @return
	 */
	@RequestMapping(value = "/batchInspection",method = RequestMethod.POST)
	public AjaxResult batchInspectionPersons(@RequestBody BatchPersonsDTO personsDTO){
	
		taskService.batchPersons(personsDTO, TicketConstants.TICKET_TASK_INSPECTION_PERSON);
		return AjaxResult.success();
	}
	
	/**
	 * 批量设置报工人
	 * @param personsDTO
	 * @return
	 */
	@RequestMapping(value = "/batchReport",method = RequestMethod.POST)
	public AjaxResult batchReportPersons(@RequestBody  BatchPersonsDTO personsDTO){
		taskService.batchPersons(personsDTO,TicketConstants.TICKET_TASK_REPORT_PERSON);
		return AjaxResult.success();
	}
	
	/**
	 * 工序状态结束
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/states/end",method = RequestMethod.POST)
	public AjaxResult modifyProcedureStates(Long id){
		if(id == null){
			return AjaxResult.success();
		}
		//todo 判断校验 数量分别提示
		taskService.modifyProcedureStates(id,TicketConstants.TICKET_STATUS_END);
		return AjaxResult.success();
	}
	
}

